<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>路线管理</span>
      </div>
      <div class="text item">
        <!-- 搜索区域 -->
        <el-form :inline="true" :model="queryParams" class="demo-form-inline">
          <el-form-item label="路线名称">
            <el-input v-model="queryParams.name" placeholder="请输入路线名称"></el-input>
          </el-form-item>
          <el-form-item label="路线类型">
            <el-select v-model="queryParams.type" placeholder="请选择路线类型" clearable>
              <el-option label="一日游" value="1"></el-option>
              <el-option label="二日游" value="2"></el-option>
              <el-option label="三日游" value="3"></el-option>
              <el-option label="多日游" value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleQuery">查询</el-button>
            <el-button v-if="checkPermission(['travel:route:add'])" type="success" @click="handleAdd">新增</el-button>
          </el-form-item>
        </el-form>

        <!-- 表格区域 -->
        <el-table :data="routeList" style="width: 100%" v-loading="loading">
          <el-table-column prop="name" label="路线名称"></el-table-column>
          <el-table-column prop="type" label="类型" width="100">
            <template slot-scope="scope">
              {{ getRouteType(scope.row.type) }}
            </template>
          </el-table-column>
          <el-table-column prop="days" label="天数" width="80"></el-table-column>
          <el-table-column prop="price" label="价格" width="100">
            <template slot-scope="scope">
              ¥{{ scope.row.price }}
            </template>
          </el-table-column>
          <el-table-column prop="description" label="描述" show-overflow-tooltip></el-table-column>
          <el-table-column prop="status" label="状态" width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
                {{ scope.row.status === 1 ? '上架' : '下架' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button v-if="checkPermission(['travel:route:edit'])" 
                type="primary" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button v-if="checkPermission(['travel:route:delete'])" 
                type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页区域 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="queryParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Route',
  data() {
    return {
      loading: false,
      total: 0,
      routeList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: '',
        type: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    checkPermission(permissions) {
      // TODO: 实现权限检查
      return true
    },
    getRouteType(type) {
      const types = {
        '1': '一日游',
        '2': '二日游',
        '3': '三日游',
        '4': '多日游'
      }
      return types[type] || '未知'
    },
    async getList() {
      this.loading = true
      try {
        // TODO: 调用路线列表API
        this.loading = false
      } catch (error) {
        this.loading = false
        console.error('获取路线列表失败:', error)
      }
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    handleAdd() {
      // TODO: 实现新增路线
    },
    handleEdit(row) {
      // TODO: 实现编辑路线
    },
    handleDelete(row) {
      // TODO: 实现删除路线
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getList()
    }
  }
}
</script>

<style scoped>
.app-container {
  padding: 20px;
}
</style> 